Skip to content

Conversation

@daniel-lxs
Copy link
Member

@daniel-lxs daniel-lxs commented Aug 21, 2025

Summary

This PR refactors the Roo provider to ensure that constructors never throw exceptions. Instead, authentication errors are now handled at the server level through HTTP status codes (e.g., 401 for unauthenticated requests).

Changes

  • RooHandler constructor no longer throws exceptions: The constructor now attempts to get a session token but proceeds with an empty/unauthenticated token if not available
  • Removed RooAuthenticationError class: This exception class is no longer needed since we're not throwing from constructors
  • Removed pre-flight authentication check: The check in ClineProvider.createTask() for the Roo provider has been removed
  • Updated error handling in webviewMessageHandler: Now uses generic error handling instead of catching specific RooAuthenticationError
  • Server-side error handling: The provider-proxy server will return appropriate HTTP status codes (401) for authentication failures

Rationale

Based on feedback from PR #7298, provider constructors should never throw exceptions. This ensures:

  1. Better separation of concerns between client initialization and server authentication
  2. More consistent error handling across all providers
  3. Graceful degradation when authentication is not available

Testing

  • Verified that RooHandler constructor succeeds even without authentication
  • Confirmed that authentication errors are properly handled by the server (401 responses)
  • Tested that the extension handles server error responses gracefully
  • All existing tests pass

Related


Important

Refactor RooHandler to avoid exceptions in constructor, handle authentication errors server-side, and update tests accordingly.

  • Behavior:
    • RooHandler constructor no longer throws exceptions; uses empty token if session token unavailable.
    • Server returns HTTP 401 for authentication failures.
  • Error Handling:
    • Removed RooAuthenticationError class.
    • Updated webviewMessageHandler to use generic error handling.
  • Testing:
    • Updated tests in roo.spec.ts to ensure RooHandler constructor does not throw exceptions.
    • Tests cover cases with unavailable CloudService, missing session token, and undefined auth service.

This description was created by Ellipsis for bbf9c13. You can customize this summary. It will automatically update as commits are pushed.

- RooHandler constructor no longer throws RooAuthenticationError
- Removed RooAuthenticationError class entirely
- Authentication errors now handled by provider-proxy server (401 responses)
- Removed pre-flight authentication check from ClineProvider.createTask
- Updated webviewMessageHandler to handle generic errors instead of RooAuthenticationError
- Client gracefully handles server error responses

This change ensures provider constructors never throw exceptions, delegating
all error handling to the server level for better separation of concerns.
@daniel-lxs daniel-lxs requested review from cte, jr and mrubens as code owners August 21, 2025 21:32
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Aug 21, 2025
Copy link
Collaborator

@cte cte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙌

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Aug 21, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Review] in Roo Code Roadmap Aug 21, 2025
Copy link
Contributor

@roomote roomote bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution! I've reviewed the changes and have some suggestions for improvement. The refactor successfully removes exceptions from the constructor as intended, following the pattern established by other providers. The main concern is ensuring all mentioned changes are included and that error handling provides appropriate user feedback.

providerName: "Roo Code Cloud",
baseURL: process.env.ROO_CODE_PROVIDER_URL ?? "https://api.roocode.com/proxy/v1",
apiKey: sessionToken,
apiKey: sessionToken || "unauthenticated", // Use a placeholder if no token
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the string "unauthenticated" as a placeholder API key could be misleading. Consider using an empty string or a more descriptive placeholder like "NO_AUTH_TOKEN" to make the intent clearer:

})
} catch (error) {
// For all errors, reset the UI and show error
await provider.postMessageToWebview({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error handling here catches all errors generically but still sends a "newChat" message on error, which might not be the intended behavior. Also, the error message shown to the user doesn't distinguish between authentication errors and other types of errors. Consider:

  1. Should we really send "newChat" on error?
  2. Could we provide more specific error messages based on the error type?

if (!sessionToken) {
throw new Error(t("common:errors.roo.authenticationRequired"))
if (CloudService.hasInstance()) {
sessionToken = CloudService.instance.authService?.getSessionToken() || ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding debug logging when falling back to an empty token (without exposing the actual token value). This could help with debugging authentication issues.

The RooHandler constructor no longer throws exceptions when authentication
is unavailable. Updated tests to expect the constructor to succeed gracefully
in all cases, delegating authentication error handling to the server level.
@cte cte merged commit 44fd643 into main Aug 21, 2025
12 of 13 checks passed
@cte cte deleted the refactor/roo-provider-no-exceptions branch August 21, 2025 21:56
@github-project-automation github-project-automation bot moved this from PR [Needs Review] to Done in Roo Code Roadmap Aug 21, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Aug 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer PR - Needs Review size:M This PR changes 30-99 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants